<?php
session_start();
ob_start();
if (!isset($_SESSION['loggedin'])) {

    header('Location: login.php');
}
?>
<?php include 'index.php';
include '../connection.php';

?>


<?php

if ( isset( $_POST['visit_date'])){
	
	$visit_date = $_POST['visit_date'];
	
}

?>
<div id="body-wrapper">

    <div id="main-content">

       

	 

           
                    
              

                    <table>
                        <thead>
                            <tr>
                              
                                <th><?= Date ?></th>
                                <th><?= Visits ?></th>
                            </tr>
                        </thead>
						
					<tfoot>
						<tr>
						                   
                                       
                                     <td style="color:red"; >All visits</td>
										<?php 
                                      $sql = "SELECT SUM(visit_num) FROM visits";
									 $result = mysql_query($sql);
									$row = mysql_fetch_array($result)
									
									?>
									
									

							  <td style = "color:blue"><?= $row['0']?></td>
						</tr>
					  </tfoot>
                       

                        <tbody>
                          
                         
                         
                          
                              <?php 

							  $sql = "SELECT * FROM visits ORDER BY date desc LIMIT 0, 2";
							  $result = mysql_query($sql);
							$match = false;	
							  while ($row = mysql_fetch_array($result)) {
							  
								
									
							  
									if($visit_date == $row['date']){
										$match = true;
									?>
										<tr>
										<td style="background-color:#00FF00" ><?= $row['date']?></td>
                                        <td style="background-color:#00FF00" ><?= $row['visit_num']?></td>
										 </tr>
								<?php	} else { ?>
								
                                          <tr>
                                       
                                        <td><?= $row['date']?></td>
                                        <td><?= $row['visit_num']?></td>

                                    </tr>
									
									<?php
									
									}//end else
									
								
									}//end while 
									
									if ( isset( $_POST['visit_date']) && $visit_date != null){
	
										
										
										$sql = "SELECT * FROM visits";
										
										  $result = mysql_query($sql);
										 $row = mysql_fetch_array($result);
										 
										
										   while ($row = mysql_fetch_array($result)) {
										   
										   if($visit_date == $row['date']){
											
											if(!$match){
											
											$match = true;
											?>
											<tr>
										<td style="background-color:#00FF00" ><?= $row['date']?></td>
                                        <td style="background-color:#00FF00" ><?= $row['visit_num']?></td>
										 </tr>
											
											<?php
											}
										   
										   }
										  
										   }
										   
										   if(!$match){
										   
										   $msg = "No Match";
										   }
										   
										   
										 ?>
											
										  	
									   
									
									
                              
	                                <?php									  
										  
	
									}
									?>
									
									
									
									
								
									    
									
									  

                              
						
                        </tbody>
						

                    </table>
					
					
						<br/>
						<form action = "" method="post">
						<p>Choose date<input type = "date" id = "visit_date" name = "visit_date"  > 
						<input type = "submit" value = "show visits" class = "button"></p>	<p style="color:red"><?= $msg?></p>
					   </form>
                </div> 
				
			

            </div> 

        </div> 





    </div> <!-- End #main-content -->

</div>